/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.stone.back.user.service;

import com.stone.back.user.dao.ICouponDao;
import com.stone.back.user.entity.BfCoupon;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 优惠劵
 * @author apple
 */
@Service
public class CouponService implements ICouponService {
    
    @Autowired
    private ICouponDao couponDao;

    @Override
    public List<BfCoupon> queryByUserid(Integer userid) {
        if(userid == null)
            return Collections.emptyList();
        return couponDao.queryByUserid(userid);
    }

    @Override
    public void addCoupon(Integer userid, String code) {
        BfCoupon entity = new BfCoupon();
        entity.setUserid(userid);
        entity.setCode(code);
        couponDao.update(entity);
    }

    @Override
    public void removeCoupan(Integer userid, Integer id) {
        if(userid == null || id == null)
            return;
        BfCoupon entity = couponDao.get(BfCoupon.class, id);
        if(entity != null && entity.getUserid().equals(userid))
            couponDao.remove(entity);
    }
    
}
